home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4019 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: news.lpr.carel.fi!usenet
  2. From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: inserting assembly code in C?
  5. Date: Thu, 01 Feb 1996 11:20:05 +0200
  6. Organization: Carelcomp Forest
  7. Message-ID: <311085C5.4EBD@cmt.lpr.mail.carel.fi>
  8. References: <4emsvo$lq4@linet02.li.net> <310FCC47.6A4@setsk0.rpi.ses.alcatel.es>
  9. NNTP-Posting-Host: renoir.cclahti.carel.fi
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b6a (WinNT; I)
  14.  
  15. 1570sw wrote:
  16. > Don Matthews wrote:
  17. > >
  18. > > I'm using Borland C compiler and I'd like to know how I would go about
  19. > > inserting some assembly code into my C programs.
  20. > >
  21. > > Thanks...
  22. > Hi!
  23. > You have tow ways:
  24. > Use the C instruction inline or put your .asm files in the project file.
  25.  
  26. Actually, inline just tells C compiler to inline the function (ie. place the function's 
  27. code at the place there would normally be code to call the function) if the compiler 
  28. finds it worthy (usually only when the function contains very few lines and speed 
  29. optimizations are used). The easiest way to include assembly code is to use the keyword 
  30. __asm:
  31.  
  32.     __asm    mov    ax,0xfe    /* One line of asm code */
  33.     __asm {            /* Multiple asm code lines */
  34.         mov    ax,0xfe
  35.         mov    bx,ax
  36.     }
  37.  
  38. Also note that if you use jumps (jmp x), you'll have to define the label outside the 
  39. assembly code:
  40.  
  41.     __asm {
  42.         mov    ax,0xfe
  43.         jmp    label
  44.     }
  45.     label:
  46.     __asm {
  47.         /* Other stuff */
  48.     }
  49.  
  50. Later,
  51.  AriL
  52. -- 
  53. All my opinions are mine and mine alone.
  54.